/**
 * @file activite.c
 * @brief Fichier source du module activite.
 *
 * @author Rachid Delory, Mamadou Keita, Florian Bernard
 */

/* *********************************************************************

                       Librairies de activite

********************************************************************* */

#include "activite.h"

/* *********************************************************************

                        Fonctions

********************************************************************* */

void init_Act(Activite * activite)
{
  if(activite)
    {
      activite->id = 0;
      activite->activite = NULL;
      activite->personne = creer_Per();
      activite->principal = NON_ACT;
      activite->maj = 0;
      activite->sup = 0;
    }
}

void liberer_Act(Activite * activite)
{
  if(activite)
    {
      activite->id = 0;
      if(activite->activite)
	{
	  free(activite->activite);
	  activite->activite = NULL;
	}
      detruire_Per(&(activite->personne));
      activite->principal = NON_ACT;
    }
}

void * creer_Act()
{
  Activite *activite;
  activite = (Activite *) malloc ( 1 * sizeof(Activite));
  init_Act(activite);
  return activite;
}

void detruire_Act(Activite ** activite)
{
  if((*activite))
    {
      liberer_Act((*activite));
      free((*activite));
      (*activite) = NULL;
    }
}

void copier_Act(Activite **dest, const Activite *src)
{
  if((*dest) == NULL)
    {
      (*dest) = creer_Act();
    }
  if(src)
    {
      (*dest)->id = src->id;
      copier_Uti(&((*dest)->activite), src->activite);
      copier_Per(&((*dest)->personne), src->personne);
      (*dest)->principal = src->principal;
    }
}

unsigned int getId_Act(const Activite * ptr)
{
  if(ptr)
    return ptr->id;
  return 0;
}

void setId_Act(Activite *ptr, const unsigned int val)
{
  if(ptr)
    ptr->id = val;
}

Personne * getPersonne_Act(const Activite * ptr)
{
  if(ptr)
    return ptr->personne;
  return NULL;
}

void setPersonne_Act(Activite *ptr, const Personne * val)
{
  if(ptr)
    {
      if(!ptr->personne)
	ptr->personne = creer_Per();
      if(val)
	copier_Per(&(ptr->personne), val);
    }
}

char * getActivite_Act(const Activite * ptr)
{
  if(ptr)
    return ptr->activite;
  return NULL;
}

void setActivite_Act(Activite *ptr, const char * val)
{
  if(ptr)
    {
      copier_Uti(&ptr->activite, val);
    }
}

char getPrincipal_Act(const Activite * ptr)
{
  if(ptr)
    return ptr->principal;
  return 0;
}

void setPrincipal_Act(Activite *ptr, const char val)
{
  if(ptr)
    ptr->principal = val;
}

void setMaj_Act(Activite *ptr, const char b)
{
  if(ptr)
    {
      ptr->maj = b;
      if(b == 1)
	ptr->sup = !b;
    }
}

char getMaj_Act(const Activite *ptr)
{
  if(ptr)
    return ptr->maj;
  return 0;
}

void setSup_Act(Activite *ptr, const char b)
{
  if(ptr)
    {
      ptr->sup = b;
      if(b == 1)
	ptr->maj = !b;
    }
}

char getSup_Act(const Activite *ptr)
{
  if(ptr)
    return ptr->sup;
  return 0;
}
